<?php

namespace app\airobot\controller;

use app\airobot\CommonLogic;
use app\airobot\model\UserModel;
use think\admin\Controller;

/**
 * 超管系统-提现管理
 * Class Withdraw
 * @package app\airobot\controller
 */
class Withdraw extends Controller
{
    private $table = 'withdraw';
    public $commonLogic;

    /**
     * 提现管理
     * @auth true
     */
    public function index()
    {
        $this->commonLogic = new CommonLogic();
        $this->title = '提现管理';
        $query = $this->_query($this->table);
        $where = [];
        if (!empty($_GET['user_id'])) {
            $where['user_id'] = $_GET['user_id'];
        }
        if (!empty($_GET['status'])) {
            $where['status'] = $_GET['status'];
        }
        $query->where($where);
        $query->order('status asc')->page();
    }

    protected function _index_page_filter(array &$data)
    {
        $this->commonLogic = new CommonLogic();
        $userIds = array_column($data, 'user_id');
        $userModel = new UserModel();
        $userList = $userModel->queryList([], ['field' => 'id', 'data' => $userIds], [], [], [], "", $field = "*", $order = "");
        $userMap = array_column($userList, null, 'id');

        foreach ($data as &$vo) {
            $vo['username'] = isset($userMap[$vo['user_id']]) ? $userMap[$vo['user_id']]['username'] : '';
            $vo['withdraw_amount'] = $this->commonLogic->DealAmount($vo['withdraw_amount']);
            $vo['charge_amount'] = $this->commonLogic->DealAmount($vo['charge_amount']);
        }
    }

    /**
     * 状态
     * @auth true
     */
    public function status()
    {
        $this->_save($this->table, $this->_vali([
            'status.in:1,2,3,4,5,6' => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]), 'id');
    }

    /**
     * 删除
     * @auth true
     */
    public function remove()
    {
        $this->_delete($this->table, 'id');
    }
}